package com.etongwl.socketlibrary;


import com.etongwl.socketlibrary.SocketManagerCore.HanderCore;
import com.etongwl.socketlibrary.SocketManagerCore.MessageCore;
import com.etongwl.socketlibrary.SocketManagerCore.ThreadCore;

/**
 * Created by jason on 16/6/27.
 * 消息队列管理
 */
public class MessageQueueManager {
    public static void manager(){
        ThreadCore threadCore=new ThreadCore(){
            @Override
            public void run() {
                super.run();
            }
        };
        threadCore.start();

        Thread thread =new Thread(){
            @Override
            public void run() {
                System.out.println("线程运行");
                HanderCore handerCore=new HanderCore(){
                    @Override
                    public void handleMessage(MessageCore msg) {
                        super.handleMessage(msg);
                        System.out.println("handleMessage is run:"+msg.toString());
                    }
                };
                int m=1000;
                for (int i =0;i<m;i++){
                    System.out.println("handleMessage for is run:"+i);
                    MessageCore msg=handerCore.obtainMessage();
                    msg.setWhat((i+1));
                    msg.setMsg("send msg content is "+i);
                    msg.sendToTarget();
                }

                MessageCore msg=handerCore.obtainMessage();
                msg.setWhat(-1);
                msg.setMsg("send msg quit ");
                msg.sendToTarget();
            }
        };

        thread.start();
    }

}
